home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / VFPRINTF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  924 b   |  29 lines

  1. /* vfprintf.c --- p 474 */
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. char filename[80] = "EXAMPLE.EXE";
  5. main()
  6. {
  7.     int line_no = 131;
  8.             /* Call the error handler to print an error message.
  9.              * First just a single line.  Then a more detailed
  10.              * message with more arguments. */
  11.     my_errmsg("Syntax error\n");
  12.     my_errmsg("File: %s at line_no %d\n", filename,
  13.                  line_no);
  14. }
  15.                     /*-------------------------------*/
  16.             /* my_errmsg: accepts variable number of arguments
  17.             * and prints their values to stderr */
  18. my_errmsg(char *p_format)
  19. {
  20.     va_list p_arg;
  21.         /* Use va_start followed by va_arg macros to get to the
  22.          * start of the variable number of arguments. This will
  23.          * alter the pointer p_arg to point to the list of
  24.          * variables to be printed. */
  25.     va_start(p_arg, p_format);
  26.     vfprintf(stderr, p_format, p_arg);
  27.             /* Use the va_end macro to reset the p_arg to NULL */
  28.     va_end(p_arg);
  29. }